<?php
require_once('./class/Role.php');

switch(@$_GET['action']){
    default:
        echo _ROLE_;
    break;

    case "addForm":
        echo Role::getAddForm();
        break;

    case "doAdd":
        $r = new Role();
        $r->setNom($_POST['nom']);
        $r->addOrModify();
        echo $r->getNom()." "._ADDED_;
        break;

    case "modifyForm":
        $r = Role::getRole($_GET['id']);
        echo $r->getModifyForm();
        break;

    case "doModify":
        $r = new Role();
        $r->setNom($_POST['nom']);
        $r->setId($_POST['id_role']);
        $r->addOrModify();
        echo _ROLE_." "._MODIFIED_;
        break;

    case "list":
        $role_array = Role::getAllRole();
        $html = '<table class="tablesorter">
						<thead>
							<th>'._ID_ROLE_.'</th>
							<th>'._NOM_ROLE_.'</th>
							<th>'._EDIT_.'</th>
							<th>'._DELETE_.'</th>
						</thead><tbody>';
        $i = 0;
        foreach($role_array as $role){
            $odd = ($i % 2 == 0) ? 'class="odd"' : "";
            $i++;
            $html .= '<tr '.$odd.'>
						<td>'.$role->getId().'</td>
						<td>'.$role->getNom().'</td>
						<td><a href="?module=role&action=modifyForm&id='.$role->getId().'">'._EDIT_.'</a></td>
						<td><a href="?module=role&action=delete&id='.$role->getId().'">'._DELETE_.'</a></td>
					</tr>';
        }
        $html .= '</tbody></table>';
        echo $html;
        break;

    case "delete":
        $r = Role::getRole($_GET['id']);
        $r->delete();
        echo $r->getNom()." "._DELETED_;
        break;
}
?>
